package com.itheima.utils;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * bean拷贝的工具类
 * @author zsj
 * @date 2023年03月15日 17:34
 */
public class BeanCopyUtils {
    //拷贝bean
    public static <T> T beanCopy(Object conyFrom,Class<T> clazz){
        T instance = null;
        try {
            instance = clazz.newInstance();
            BeanUtils.copyProperties(conyFrom,instance);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return instance;
    }
    //拷贝集合
    public static <T> List<T> beanListCopy(List<? extends Object> fromList,Class<T> clazz){
        return fromList.stream()
                .map(o -> beanCopy(o, clazz))
                .collect(Collectors.toList());
    }

}
